package com.swpu.service_food.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.swpu.commonutils.R;
import com.swpu.service_food.entity.Food;
import com.swpu.service_food.entity.FoodCategory;
import com.swpu.service_food.entity.vo.FoodCategoryVo;
import com.swpu.service_food.mapper.FoodMapper;
import com.swpu.service_food.service.FoodCategoryService;
import com.swpu.service_food.service.FoodService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chaichai
 * @since 2024-01-26
 */
@Service
public class FoodServiceImpl extends ServiceImpl<FoodMapper, Food> implements FoodService {

    @Autowired
    private FoodCategoryService foodCategoryService;
    @Override
    public List<FoodCategoryVo> getFoodListInfo() {
        List<FoodCategory> foodCategories = foodCategoryService.getAllFoodCategory();
        List<Food> allFood = baseMapper.getAllFood();
       List foodCategoryVoList = new ArrayList<FoodCategoryVo>();
        for (int i = 0; i < foodCategories.size(); i++) {
            FoodCategory currentFoodCate=foodCategories.get(i);
            FoodCategoryVo foodCategoryVo = new FoodCategoryVo();
            foodCategoryVo.setCategoryName(currentFoodCate.getCategoryName());
            foodCategoryVo.setId(currentFoodCate.getId());
            List foodList = new ArrayList<Food>();
            for (Food food: allFood) {
                if (food.getCategoryId().equals(currentFoodCate.getId())){
                    foodList.add(food);
                }
            }
            foodCategoryVo.setFoodList(foodList);
            foodCategoryVoList.add(foodCategoryVo);
        }

        return foodCategoryVoList;
    }
}
